package com.shengzai

import scala.io.Source

//取 学生总分
object Code38Example02 {
  def main(args: Array[String]): Unit = {
    val scoreList: List[String] = Source.fromFile("hadoop_code/src/data/score.txt").getLines().toList

    scoreList.map(
      (line: String) => {
        val scoreSplit: Array[String] = line.split(",")
        val sid: String = scoreSplit(0)
        val score: String = scoreSplit.last
        (sid, score)
      }
    ).groupBy(_._1).map(
      (tuple2) => {
        var sum: Int = 0
        for (elem <- tuple2._2) {
          sum += elem._2.toInt
        }
        (tuple2._1, sum)
      }
    ).toList.sortBy(_._1).foreach(println)



  }

}
case class score(sid:String,cid:String,score:Int)
